<template>
    <div class="category">
        <div id="separator">{{ categoryId }}</div>
        <div class="product" @click="clickProduct(product.productId)" v-for="(product, index) of productList" :key="`product-${index}`" :style="{'background-image': `url(http://192.168.31.68:80/${product.picture})`}">
            <div class="backgroundProcess"></div>
            <div class="productText">
                <div class="title">{{product.name}}</div>
                <div class="explain">{{product.productId}}</div>
            </div>
        </div>
    </div>
</template>

<script>
import { mapMutations, mapActions } from 'vuex'

export default {
    data(){
        return {
            categoryId: null,
            productList: null
        }
    },
    methods: {
        ...mapMutations({
            changeVisible: 'floatWindow/changeVisible',
            setProductId: 'product/setProductId',
            changeInnerComponent: 'floatWindow/changeInnerComponent'
        }),
        ...mapActions({
            getProductListByCategoryId: 'product/getProductListByCategoryId'
        }),
        clickProduct(productId) {
            this.setProductId(productId)
            this.changeVisible()
            this.changeInnerComponent('FlexProduct')
        }
    },
    mounted() {
        let categoryId = this.$route.params.categoryId
        this.categoryId = categoryId
        console.log(this.categoryId)
        this.getProductListByCategoryId(this.categoryId).then((res) => {
            console.log(res)
            this.productList = res
        }, (error) => {
            console.log(error)
        })
    }
}
</script>

<style lang="scss" scoped>
#separator
{
    border: none;
    border-bottom: 3px solid #364462;
    text-align: center;
    overflow: hidden;
    width: 20%;
    margin: 35px auto;
    font-size: 2em;
    color: #364462;
}

.product
{
    cursor: pointer;
    border: none;
    position: relative;
    overflow: hidden;
    border-radius: 2px;
    height: 400px;
    width: 1344px;
    margin: 70px auto;
    background-color: #efe7db;
    box-shadow: 2px 2px 15px #78a686;
    transition: all 0.2s cubic-bezier(0.55, 0.085, 0.68, 0.53);
    background-size: cover;
}

.backgroundProcess
{
    position: absolute;
    z-index: 1;
    background-color: rgba(0, 0, 0, 0);
    backdrop-filter: brightness(35%);
    width: 55%;
    height: 100%;
    top: 0;
    left: 0;
}

.productText
{
    position: absolute;
    left: 8%;
    width: 60%;
    height: 100%;
    z-index: 2;
}

.product .title
{
    margin-top: 8%;
    float: left;
    color: #efe7db;
    font-size: 2.3em;
    font-weight: lighter;
}

.product .explain
{
    margin-top: 5%;
    float: left;
    clear: left;
    font-size: 1.2em;
    color: #efe7db;
    font-weight: lighter;
}

.product:hover
{
    transform: scale(1.04);
}
</style>